package com.hwd.gmall.seckill.controller;

import com.hwd.gmall.common.result.Result;
import com.hwd.gmall.model.activity.SeckillGoods;
import com.hwd.gmall.seckill.service.SeckillGoodsService;
import com.hwd.gmall.seckill.util.DateUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 秒杀微服务的控制层
 *
 * @author 黄伟东/Victor
 * @date 2022/5/11 18:29
 */
@RestController
@RequestMapping(value = "/seckill/goods")
public class IndexController {

    @Resource
    private SeckillGoodsService seckillGoodsService;

    /**
     * 查询首页的时间段
     *
     * @return com.hwd.gmall.common.result.Result<java.util.List < java.util.Date>>
     */
    @GetMapping(value = "/listIndexDates")
    public Result<List<Date>> listIndexDates() {
        return Result.ok(DateUtil.getDateMenus());
    }

    /**
     * 查询指定时间段的所有秒杀商品的列表
     *
     * @param startTime 指定时间段的开始时间
     * @return com.hwd.gmall.common.result.Result<java.util.List < com.hwd.gmall.model.activity.SeckillGoods>>
     */
    @GetMapping(value = "/listSeckillGoods")
    public Result<List<SeckillGoods>> listSeckillGoods(String startTime) {
        return Result.ok(seckillGoodsService.listSeckillGoods(startTime));
    }

    /**
     * 查询指定的秒杀商品数据
     *
     * @param startTime 指定时间段的开始时间
     * @param goodsId   商品id
     * @return com.hwd.gmall.common.result.Result<com.hwd.gmall.model.activity.SeckillGoods>
     */
    @GetMapping(value = "/getSeckillGoods")
    public Result<SeckillGoods> getSeckillGoods(String startTime, String goodsId) {
        return Result.ok(seckillGoodsService.getSeckillGoods(startTime, goodsId));
    }
}
